package hottargui.domain.gamma;

import hottargui.domain.*;

public class GammaEndRoundStrategyImpl implements EndRoundStrategy {

	private DeckOfCards _deck;
	private int diceValue;
	private int counter;
	private StateMachine _sm; 

	public GammaEndRoundStrategyImpl(StateMachine sm, DeckOfCards deck){
		counter = 0;
		_deck = deck;
		diceValue = deck.getCurrentDeckBasedDiceValue();
		_sm = sm;
	}


	public State calculateEndOfRound() {


		if (diceValue == 6 && counter == 0)
		{
			counter++;
			return State.move;
		} 
		else {
			counter = 0;

			_deck.takeCardFormTopOfDeck();
			_sm.doUpdateDeck(_deck);

			if (_deck.countCardsInDeck()==0) {
				return State.endRound;
			}
			else	{		  
				//System.out.println("Antal cards i deck " + _deck.countCardsInDeck() );
				return State.endTurn;

			}  
		}

	}	  




	public boolean diceRollAllowed() {
		if (_deck.countCardsInDeck()==0){

			return true;

		}	
		else
			return false;
	}





	public void doUpdateDeck(DeckOfCards deck) {
		_deck = deck;
	}




	public void setDeckOfCards(DeckOfCards deck) {
		_deck = deck;	
		diceValue = deck.getCurrentDeckBasedDiceValue();
	}





}
